<template>
  <j-modal
    title="项目列表"
    :visible="visible"
    ok-text=""
    :footer="null"
    :ok-button-props="{ props: { disabled: true } }"
    :fullscreen="true"
    @close="close"
  >
    <a-card :bordered="false">
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="false"
        :loading="loading"
      >
        <span slot="switch" slot-scope="text, record">
          <a-switch
            @change="changeStatus(record)"
            :checked="getSataus(record['projectStatus'])"
            checked-children="上线"
            un-checked-children="下线"
          />
        </span>
        <span slot="actionName">
          <a-button size="small" @click="openCreatProject()" type="primary" icon="plus">新增</a-button>
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleProjectCheck(record, '')">查看</a>
          <template v-if="record.projectStatus == '0'">
            <a-divider type="vertical" />
            <a @click="handleEdit(record, '人员编辑')">编辑</a>
            <a-divider type="vertical" />
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
              <a>删除</a>
            </a-popconfirm>
          </template>
        </span>
      </a-table>
      <!-- table区域-end -->
      <createProject ref="createProject" @ok="modalFormOk"></createProject>
      <typeListModel ref="modalForm" @ok="modalFormOk"></typeListModel>
      <projectCheck ref="projectCheck"></projectCheck>
    </a-card>
  </j-modal>
</template>
<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { httpAction, getAction, postAction, deleteAction } from '@/api/manage'
import columns from './projectListModelColumns'
import createProject from './createProject'
import typeListModel from './typeListModel'
import projectCheck from './projectCheck'

export default {
  name: 'projectListModal',
  mixins: [JeecgListMixin],
  components: {
    createProject,
    typeListModel,
    projectCheck,
  },
  data() {
    return {
      // 表头
      columns: columns(this),
      queryParam: {},
      url: {
        list: '/performcheck/checkProjectInfo/queryProjectList',
        status: '/performcheck/checkProjectInfo/switchProjectStatus',
        delete: '/performcheck/checkProjectInfo/deleteProject',
      },
      visible: false,
      dataSource: [],
    }
  },
  computed: {},
  methods: {
    handleProjectCheck(record) {
      this.$refs.projectCheck.check(record)
    },
    getSataus(status) {
      if (status == 0) {
        return false
      } else {
        return true
      }
    },
    changeStatus(record) {
      httpAction(
        this.url.status,
        {
          id: record.id,
          projectStatus: record.projectStatus == '0' ? '1' : '0',
        },
        'put'
      ).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.error(res.message)
        }
      })
    },
    edit(record) {
      this.dataSource = []
      this.queryParam.templateId = Object.assign({}, record).id
      this.loadData()
      this.visible = true
    },
    openCreatProject() {
      this.$refs.createProject.add(this.queryParam.templateId)
    },
    close() {
      this.visible = false
      this.$emit('ok')
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>